﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity.Framework;
using System.Data.Objects;

namespace Business.Operations
{
    public class StatOperation
    {
        private static HPDMASEntities db = new HPDMASEntities();

        public StatOperation()
        {

        }

        public static List<Stat> StatGetAll()
        {
            var statListesi = db.Stat.ToList();
            return statListesi;
        }

        public static Stat StatGetByStatId(int statId)
        {
            var stat = (from c in db.Stat where c.StatID == statId select c).First();
            return stat;
        }

        public static void StatDelete(int statId)
        {
            Stat k = (from c in db.Stat where c.StatID == statId select c).First();
            db.DeleteObject(k);
            db.SaveChanges();
        }

        public static void StatInsert(Stat stat)
        {
            db.Stat.AddObject(stat);
            db.SaveChanges();
        }

        public static int StatIdGetByStatAdi(string statAdi)
        {
            var statId = (from c in db.Stat where c.StatAdi == statAdi select c.StatID).First();
            return statId;
        }

        public static List<string> StatAdiGetByIlceIdAndSehirId(int ilceId, int sehirId)
        {
            var statAdi = (from c in db.StatSehir where c.IlceID == ilceId && c.SehirID == sehirId select c.Stat.StatAdi).ToList();
            return statAdi;
        }

        public static List<string> StatAdiGetBySehirId(int sehirId)
        {
            var statAdi = db.StatSehir.
                Where(c => c.SehirID == sehirId).
                Select(c => c.Stat.StatAdi);
            return statAdi.ToList();
        }
    }
}
